Contextual typing for return expressions of functions with contextual signatures based on instantiated types#61185
Conversation
… signatures based on instantiated types
|
@jakebailey would you be so kind and run tests here? :) |
9055e55 to
a45dfbb
Compare
| // prevent inference candidates of outer inference context to provide contextual type information for the expressions within the inner context | ||
| // that could turn fresh literal candidates in the inner context into regular types for union-like literals (such as booleans and enums) | ||
| // and that would create mismatches between inferred types for outer and inner contexts which is especially problematic when invariant type parameters are involved | ||
| // | ||
| // the call below should be ok but with the inner one receiving `boolean` as contextual type it would infer `true` for its type parameter | ||
| // and that would create outer signature applicability error with outer `Box<boolean>` and inner `Box<true>` | ||
| // | ||
| // interface Box<T> { v: (arg: T) => T; } | ||
| // declare function invariantBox<T>(v: T): Box<T> | ||
| // declare function fn<T>(arg: Box<T>, get: () => Box<T>): void; | ||
| // fn(invariantBox(true), () => invariantBox(true)); |
There was a problem hiding this comment.
this problem is quite similar to #48363 , #59754 and #61196
So it feels like some consistent approach could be used to fix those and to remove this branch. But that problem is out of the scope of this PR so I'm not attempting to deal with it. Thanks to this branch the behavior should be no worse than the existing one.
…-for-returns-of-contextual-signatures
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
This expands on #30568 (in a way)
fixes #61197